/*
 * @lc app=leetcode.cn id=228 lang=javascript
 *
 * [228] 汇总区间
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {string[]}
 */
var summaryRanges = function (nums) {
  let p1 = 0;
  let p2 = 0;
  const res = [];
  while (p2 !== nums.length) {
    const num1 = nums[p2];
    const num2 = nums[p2 + 1];
    let state = false;
    if (num1 + 1 !== num2) {
      res.push(p1 === p2 ? `${num1}` : `${nums[p1]}->${num1}`);
      state = true;
    }
    p2++;
    state && (p1 = p2);
  }
  return res;
};
// @lc code=end
